#Requires AutoHotkey v2.0

font:="微软雅黑"
version := "v1.3.8"
author := "by谪仙"
userType := A_IsAdmin ? "管理员" : "普通用户"

MyGui := Gui()
MyGui.SetFont(, font)
MyGui.Title := "Win快速跳转工具  " version "  " author "  (" userType ")"

MyGui.OnEvent("Close", (*) => ExitApp()) ; 主窗口关闭时结束脚本

tab := MyGui.Add("Tab3", , ["快速功能", "优化"])
tab.UseTab(1)
{
    ; 第一行
    devmgmt := MyGui.Add("Button", "x20 y35 w90", "设备管理器")
    devmgmt.OnEvent("Click", (*) => Run("devmgmt.msc"))

    printer := MyGui.Add("Button", "x+5 yp w90", "打印机") ; x+5表示在前一个控件右侧10像素，yp保持同一行
    printer.OnEvent("Click", (*) => Run("ms-settings:printers"))


    CredentialManager := MyGui.Add("Button", "x+5 yp w90", "凭据管理器")
    CredentialManager.OnEvent("Click", (*) => Run("control /name Microsoft.CredentialManager"))
    windowsdefender := MyGui.Add("Button", "x+5 yp w90", "安全中心")
    windowsdefender.OnEvent("Click", (*) => Run("ms-settings:windowsdefender"))

    ; 新一行
    ; 网络适配器
    ncpa := MyGui.Add("Button", "x20 y+5 w90", "网络适配器")
    ncpa.OnEvent("Click", (*) => Run("ncpa.cpl"))

    ; 设置-网络
    network := MyGui.Add("Button", "x+5 yp w90", "设置-网络")
    network.OnEvent("Click", (*) => Run("ms-settings:network-status"))

    ; 网络工具
    ipinfo := MyGui.Add("Button", "x+5 yp w90", ">网络工具")
    ipinfo.OnEvent("Click", GetIPInfo)

    ; 飞行模式
    flymode := MyGui.Add("Button", "x+5 yp w90", "飞行模式")
    flymode.OnEvent("Click", (*) => Run("ms-settings:proximity"))

    ; 新一行
    fsmgmt := MyGui.Add("Button", "x20 y+5 w90", "共享管理")
    fsmgmt.OnEvent("Click", (*) => Run("fsmgmt.msc"))

    ; 本地共享
    localshare := MyGui.Add("Button", "x+5 yp w90", "本地共享")
    localshare.OnEvent("Click", (*) => Run("\\localhost"))

    ; 访问共享
    shared := MyGui.Add("Button", "x+5 yp w90", "访问共享")
    shared.OnEvent("Click", ToShared)

    ; 断开共享访问
    delNetUse := MyGui.Add("Button", "x+5 yp w90", "断开共享访问")
    ; delNetUse.OnEvent("Click", (*) => Run("net use * /del"))
    delNetUse.OnEvent("Click", delNetUseF)

    ; 新一行
    controlpanel := MyGui.Add("Button", "x20 y+5 w90", "控制面板")
    controlpanel.OnEvent("Click", (*) => Run("control.exe"))
    regedit := MyGui.Add("Button", "x+5 yp w90", "注册表编辑器")
    regedit.OnEvent("Click", (*) => Run("regedit"))
    services := MyGui.Add("Button", "x+5 yp w90", "服务")
    services.OnEvent("Click", (*) => Run("services.msc"))
    taskmgr := MyGui.Add("Button", "x+5 yp w90", "任务管理器")
    taskmgr.OnEvent("Click", (*) => Run("taskmgr"))

    ; 新一行
    eventvwr := MyGui.Add("Button", "x20 y+5 w90", "事件查看器")
    eventvwr.OnEvent("Click", (*) => Run("eventvwr.msc"))

    ; 资源监视器
    resourcemonitor := MyGui.Add("Button", "x+5 yp w90", "资源监视器")
    resourcemonitor.OnEvent("Click", (*) => Run("Resmon"))
    ; resourcemonitor.OnEvent("Click", (*) => Run("perfmon.exe /res"))
    sysprops := MyGui.Add("Button", "x+5 yp w90", "系统属性")
    sysprops.OnEvent("Click", (*) => Run("sysdm.cpl"))
    sysabout := MyGui.Add("Button", "x+5 yp w90", "关于Windows")
    sysabout.OnEvent("Click", (*) => Run("ms-settings:about"))

    ; 新一行
    OptionalFeatures := MyGui.Add("Button", "x20 y+5 w90", "可选功能")
    OptionalFeatures.OnEvent("Click", (*) => Run("ms-settings:optionalfeatures"))
    ; FeaturesMgr := MyGui.Add("Button", "x+5 yp w90", "Windows功能")
    ; FeaturesMgrFile := "C:\Windows\System32\OptionalFeatures.exe"
    ; if FileExist(FeaturesMgrFile) {
    ;     FeaturesMgr.OnEvent("Click", (*) => Run(FeaturesMgrFile))
    ; } else {
    ;     FeaturesMgrFile := "C:\Windows\SysNative\OptionalFeatures.exe"
    ;     if FileExist(FeaturesMgrFile) {
    ;         FeaturesMgr.OnEvent("Click", (*) => Run(FeaturesMgrFile))
    ;     } else {
    ;         MsgBox("OptionalFeatures.exe在系统目录中不存在")
    ;     }
    ; }
    optionalfeatures := MyGui.Add("Button", "x+5 yp w90", "Windows功能")
    optionalfeatures.OnEvent("Click", (*) => Run("optionalfeatures"))
    appwiz := MyGui.Add("Button", "x+5 yp w90", "程序")
    appwiz.OnEvent("Click", (*) => Run("appwiz.cpl"))
    defaultapps := MyGui.Add("Button", "x+5 yp w90", "默认应用")
    defaultapps.OnEvent("Click", (*) => Run("ms-settings:defaultapps"))

    ; 新一行
    startupapps := MyGui.Add("Button", "x20 y+5 w90", "启动项")
    startupapps.OnEvent("Click", (*) => Run("ms-settings:startupapps"))
    lusrmgr := MyGui.Add("Button", "x+5 yp w90", "本地用户和组")
    lusrmgr.OnEvent("Click", (*) => Run("lusrmgr.msc"))

    ; 用户账户
    useraccount := MyGui.Add("Button", "x+5 yp w90", "用户账户")
    useraccount.OnEvent("Click", (*) => Run("netplwiz"))
    

    ; 防火墙
    firewall := MyGui.Add("Button", "x+5 yp w90", "防火墙")
    firewall.OnEvent("Click", (*) => Run("firewall.cpl"))

    ; 新一行
    ; 修复
    recovery := MyGui.Add("Button", "x20 y+5 w90", "系统修复")
    recovery.OnEvent("Click", Frecovery)

    ; 检查磁盘错误
    chkdsk := MyGui.Add("Button", "x+5 yp w90", "磁盘检查修复")
    chkdsk.OnEvent("Click", DiskCheck)

    ; 用户账户控制
    uac := MyGui.Add("Button", "x+5 yp w90", "用户账户控制")
    uac.OnEvent("Click", (*) => Run("UserAccountControlSettings"))

    ; 存储
    stormgmt := MyGui.Add("Button", "x+5 yp w90", "存储管理")
    stormgmt.OnEvent("Click", (*) => Run("ms-settings:storagesense"))

    ; 新一行
    ; 清理图标缓存
    delIconCache := MyGui.Add("Button", "x20 y+5 w90", "清理图标缓存")
    delIconCache.OnEvent("Click", DelIconCacheF)

    ; 清理temp目录
    delTemp := MyGui.Add("Button", "x+5 yp w90", "清理temp目录")
    delTemp.OnEvent("Click", DelTempF)

    ; 组策略
    gpedit := MyGui.Add("Button", "x+5 yp w90", "组策略")
    gpedit.OnEvent("Click", (*) => Run("gpedit.msc"))

    ; secpol.msc
    secpol := MyGui.Add("Button", "x+5 yp w90", "安全策略")
    secpol.OnEvent("Click", (*) => Run("secpol.msc"))

    ; 新一行
    ; Edge配置清空
    edgeX := MyGui.Add("Button", "x20 y+5 w90", "Edge配置清空")
    edgeX.OnEvent("Click", EdgeConfigClear)


    ; 重启资源管理器
    restartExplorer := MyGui.Add("Button", "x+5 yp w90", "重启资源管理器")
    ; restartExplorer.OnEvent("Click", (*) => Run('powershell -Command "Get-Process explorer | Stop-Process -Force"'))
    ; restartExplorer.OnEvent("Click", (*) => Run('cmd.exe /c taskkill /f /im explorer.exe & start explorer.exe'))
    restartExplorer.OnEvent("Click", (*) => Run('powershell Stop-Process -Name "explorer" -Force'))

    ; 屏幕键盘
    keyboard := MyGui.Add("Button", "x+5 yp w90", "屏幕键盘")
    keyboard.OnEvent("Click", (*) => Run("osk"))

    ; 电源
    power := MyGui.Add("Button", "x+5 yp w90", ">电源")
    power.OnEvent("Click", PowerF)

    ; 新一行
    ; msconfig
    msconfig := MyGui.Add("Button", "x20 y+5 w90", "系统配置")
    msconfig.OnEvent("Click", (*) => Run("msconfig"))

    timedate := MyGui.Add("Button", "x+5 yp w90", "时间日期")
    timedate.OnEvent("Click", (*) => Run("timedate.cpl"))

    mmsys:= MyGui.Add("Button", "x+5 yp w90", "声音")
    mmsys.OnEvent("Click", (*) => Run("mmsys.cpl"))

    inetcpl := MyGui.Add("Button", "x+5 yp w90", "Internet属性")
    inetcpl.OnEvent("Click", (*) => Run("inetcpl.cpl"))

    ; 新一行
    ; mstsc
    mstsc := MyGui.Add("Button", "x20 y+5 w90", "远程桌面")
    mstsc.OnEvent("Click", (*) => Run("mstsc"))

    ; 打印队列清理
    printqueue := MyGui.Add("Button", "x+5 yp w90", "打印队列清理")
    printqueue.OnEvent("Click", printqueueF)

    ; 任务计划程序
    taskschd := MyGui.Add("Button", "x+5 yp w90", "任务计划程序")
    taskschd.OnEvent("Click", (*) => Run("taskschd.msc"))
    
    ; snippingtool
    snippingtool := MyGui.Add("Button", "x+5 yp w90", "截图")
    snippingtool.OnEvent("Click", (*) => Run("snippingtool"))

    ; 新一行
    ; 桌面图标
    deskIcon := MyGui.Add("Button", "x20 y+5 w90", "桌面图标")
    deskIcon.OnEvent("Click", (*) => Run('rundll32 shell32.dll,Control_RunDLL desk.cpl,,0'))

    ; 证书
    certmgr := MyGui.Add("Button", "x+5 yp w90", "证书")
    certmgr.OnEvent("Click", (*) => Run('certmgr.msc'))

    ; 性能设置SystemPropertiesPerformance.exe 
    performance := MyGui.Add("Button", "x+5 yp w90", "性能设置")
    performance.OnEvent("Click", (*) => Run('SystemPropertiesPerformance.exe'))

    ; 环境变量
    environment := MyGui.Add("Button", "x+5 yp w90", "环境变量")
    environment.OnEvent("Click", (*) => Run('rundll32 sysdm.cpl,EditEnvironmentVariables'))

    ; 新一行
    ; 高级启动
    advanced := MyGui.Add("Button", "x20 y+5 w90", "高级启动")
    ; advanced.OnEvent("Click", (*) => Run('shutdown /r /o /f /t 0'))
    advanced.OnEvent("Click", AdvancedStartup)

    ; 共享信息
    shareInfo := MyGui.Add("Button", "x+5 yp w90", ">共享信息")
    shareInfo.OnEvent("Click", shareInfoF)

    ; 切换到管理员模式
    admin := MyGui.Add("Button", "x+5 yp w90", "管理员模式")
    admin.OnEvent("Click", toAdmin)

    





















}

tab.UseTab(2)
{
    ; 关闭系统预留空间
    btclosespace := MyGui.Add("Button", "x20 y35 ", "关闭预留空间")
    btclosespace.OnEvent("Click", (*) => (confAdmin(),Run("DISM /Online /Set-ReservedStorageState /State:Disabled")))

    ; 关闭BitLocker加密
    btclosebitlocker := MyGui.Add("Button", "x+5 yp ", "关闭设备加密")
    btclosebitlocker.OnEvent("Click", closebitlockerF)

    ; 禁用sysMain
    btsysMain := MyGui.Add("Button", "x+5 yp ", "禁用sysMain")
    btsysMain.OnEvent("Click", DisSysMain)

    ; 禁用Windows Search 服务
    btsearch := MyGui.Add("Button", "x+5 yp ", "禁用WSearch")
    btsearch.OnEvent("Click", BanWSearch)

    ; 解除程序文件风险警告
    btProgramWarning := MyGui.Add("Button", "x20 y+5", "解除程序风险警告")
    btProgramWarning.OnEvent("Click", (*) => Run('reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Associations" /v "ModRiskFileTypes" /t REG_SZ /d ".bat;.exe;.reg;.vbs;.chm;.msi;.js;.cmd" /f'))

    ; 手动更新
    manualUpdate := MyGui.Add("Button", "x+5 yp ", "手动更新")
    manualUpdate.OnEvent("Click", manualUpdateF)

    ; 显示扩展名
    showExt := MyGui.Add("Button", "x+5 yp ", "显示扩展名")
    showExt.OnEvent("Click", (*) => Run('reg add "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced" /v "HideFileExt" /t REG_DWORD /d "0" /f'))

    ; 右键添加管理员打开
    addAdminOpen := MyGui.Add("Button", "x+5 yp ", "右键管理员打开")
    addAdminOpen.OnEvent("Click", addAdminOpenF)

    ; 右键重启资源管理器
    addRestartExplorer := MyGui.Add("Button", "x20 y+5 ", "右键重启资源管理器 ")
    addRestartExplorer.OnEvent("Click",addRestartExplorerF)

    ; 删除导航栏中的图库
    delNavGallery := MyGui.Add("Button", "x+5 yp ", "删除导航栏图库 ")
    delNavGallery.OnEvent("Click", (*) => Run('Reg.exe add "HKCU\Software\Classes\CLSID\{e88865ea-0e1c-4e20-9aa6-edcd0212c87c}" /v "System.IsPinnedToNameSpaceTree" /t REG_DWORD /d "0" /f'))

    ; 删除导航栏主文件夹
    delNavMain := MyGui.Add("Button", "x+5 yp ", "删除导航栏主文件夹")
    delNavMain.OnEvent("Click", (*) => Run('Reg.exe delete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace\{f874310e-b6b7-47dc-bc84-b9e6b38f5903}" /f'))

    ; 移除左侧重复卷
    delNavDupVol := MyGui.Add("Button", "x20 y+5", "移除左侧重复卷")
    delNavDupVol.OnEvent("Click", (*) => Run('reg delete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace\DelegateFolders\{F5FB2C77-0E2F-4A16-A381-3E560C68BC83}" /f'))

    ; 右键复制路径
    copyPath := MyGui.Add("Button", "x+5 yp ", "右键复制路径")
    copyPath.OnEvent("Click", copyPathF)

    ; 显示此电脑
    showThisPC := MyGui.Add("Button", "x+5 yp ", "显示此电脑")
    showThisPC.OnEvent("Click",showThisPCF)

    ; 资源管理器打开到此电脑
    openThisPC := MyGui.Add("Button", "x+5 yp ", "打开到此电脑")
    openThisPC.OnEvent("Click", (*) => Run('reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" /v "LaunchTo" /t REG_DWORD /d "1" /f'))
    
    ; 不添加快捷方式字样
    delShortcutTxt := MyGui.Add("Button", "x20 y+5", "不加快捷方式字样")
    delShortcutTxt.OnEvent("Click", (*) => Run('reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer" /v "Link" /t REG_BINARY /d "00000000" /f'))

    ; 搜索框为图标
    searchIcon:= MyGui.Add("Button", "x+5 yp ", "搜索框为图标")
    searchIcon.OnEvent("Click", (*) => Run('reg add "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Search" /v "SearchboxTaskbarMode" /t REG_DWORD /d "1" /f'))

    ; 隐藏七个库
    hide7Lib := MyGui.Add("Button", "x+5 yp", "隐藏七个库")
    hide7Lib.OnEvent("Click", hide7LibF)

    ; 默认打开小键盘
    defaultKeyboard := MyGui.Add("Button", "x+5 yp ", "默认小键盘")
    defaultKeyboard.OnEvent("Click", (*) => Run('reg add "HKU\.DEFAULT\Control Panel\Keyboard" /v "InitialKeyboardIndicators" /t REG_SZ /d "2" /f'))

    ; 快速访问不显示常用文件夹
    quikNoCommon:= MyGui.Add("Button", "x20 y+5", "隐藏常用目录")
    quikNoCommon.OnEvent("Click", (*) => Run('reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer" /v "ShowFrequent" /t REG_DWORD /d "0" /f'))

    ; 快速访问不显示最近文档
    quikNoRecent := MyGui.Add("Button", "x+5 yp", "隐藏最近文档")
    quikNoRecent.OnEvent("Click", (*) => Run('reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer" /v "ShowRecent" /t REG_DWORD /d "0" /f'))

    ; 恢复经典右键菜单
    classicRight := MyGui.Add("Button", "x+5 yp", "经典右键菜单")
    classicRight.OnEvent("Click", (*) => Run('reg add "HKCU\Software\Classes\CLSID\{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}\InprocServer32" /ve /t REG_SZ /d "" /f'))

    ; 禁止自动播放
    noAutoPlay := MyGui.Add("Button", "x+5 yp ", "禁止自动播放")
    noAutoPlay.OnEvent("Click", noAutoPlayF)

    ; 解除路径长度限制
    longPathEnable := MyGui.Add("Button", "x20 y+5 ", "解除路径长度限制")
    longPathEnable.OnEvent("Click", (*) => Run('reg add "HKLM\SYSTEM\CurrentControlSet\Control\FileSystem" /v "LongPathsEnabled" /t REG_DWORD /d "1" /f'))

    ; Win11任务栏靠左
    leftTaskbar := MyGui.Add("Button", "x+5 yp ", "Win11任务栏靠左")
    leftTaskbar.OnEvent("Click", (*) => Run('reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" /v "TaskbarAl" /t REG_DWORD /d "0" /f'))

    ; 启用不安全的来宾登录
    allowInsecureGuestAuth := MyGui.Add("Button", "x+5 yp ", "启用不安全的来宾登录")
    allowInsecureGuestAuth.OnEvent("Click", allowInsecureGuestAuthF)

    ; 关闭防火墙
    closeFirewall := MyGui.Add("Button", "x20 y+5 ", "关闭防火墙")
    closeFirewall.OnEvent("Click", (*) => (confAdmin(),RunWait('netsh advfirewall set allprofiles state off')))

    ; 允许空密码用户登录
    allowEmptyPassword := MyGui.Add("Button", "x+5 yp ", "允许空密码")
    allowEmptyPassword.OnEvent("Click", (*) => Run('reg add "HKLM\SYSTEM\ControlSet001\Control\Lsa" /v "LimitBlankPasswordUse" /t REG_DWORD /d "0" /f'))

    ; 控制面板大图标
    controlPBigIcon := MyGui.Add("Button", "x+5 yp ", "控制面板大图标")
    controlPBigIcon.OnEvent("Click", controlPBigIconF)

    ; 剪贴板历史
    clipboardHistory := MyGui.Add("Button", "x+5 yp ", "剪贴板历史启用")
    clipboardHistory.OnEvent("Click", (*) => Run('reg add "HKCU\Software\Microsoft\Clipboard" /v "EnableClipboardHistory" /t REG_DWORD /d "1" /f'))

    ; 删除此电脑中所有软件图标
    delThisPCsIcon := MyGui.Add("Button", "x20 y+5 ", "删除此电脑中所有软件图标")
    delThisPCsIcon.OnEvent("Click", delThisPCsIconF)

    ; 启用LPD打印服务和LPR端口监视器
    enableLPD := MyGui.Add("Button", "x+5 yp ", "启用LPD打印服务")
    enableLPD.OnEvent("Click", enableLPDF)

    ; 修复网络发现不能启用
    fixNetDiscover := MyGui.Add("Button", "x+5 yp ", "修复网络发现")
    fixNetDiscover.OnEvent("Click", fixNetDiscoverF)

    ; 暂停更新到2042年
    pauseUpdate2042 := MyGui.Add("Button", "x20 y+5 ", "暂停更新到 2042年")
    pauseUpdate2042.OnEvent("Click", pauseUpdate2042F)

    ; 禁用菜单显示延迟
    disableMenuDelay := MyGui.Add("Button", "x+5 yp ", "禁用菜单延迟")
    disableMenuDelay.OnEvent("Click", (*) => Run('reg add "HKCU\Control Panel\Desktop" /v "MenuShowDelay" /t REG_SZ /d "0" /f'))

    
    ; 禁用基于虚拟化的安全性
    disableVBS := MyGui.Add("Button", "x+5 yp ", "禁用基于虚拟化的安全性")
    disableVBS.OnEvent("Click", disableVBSF)

    ; 新一行
    ; 禁用内存完整性
    disableMemoryIntegrity := MyGui.Add("Button", "x20 y+5 ", "禁用内存完整性")
    disableMemoryIntegrity.OnEvent("Click", (*) => Run('reg add "HKLM\System\CurrentControlSet\Control\DeviceGuard\Scenarios\HypervisorEnforcedCodeIntegrity" /v "Enabled" /t REG_DWORD /d 0 /f'))








}

MyGui.Show()

;@Ahk2Exe-IgnoreBegin

;@Ahk2Exe-IgnoreEnd
; ==============================================
disableVBSF(*) {
    if(!confAdmin()){
        return
    }
    Run('reg add "HKLM\software\policies\microsoft\windows\DeviceGuard" /v "EnableVirtualizationBasedSecurity" /t REG_DWORD /d 0 /f')
    Run('reg add "HKLM\software\policies\microsoft\windows\DeviceGuard" /v "HVCIMATRequired" /t REG_DWORD /d 0 /f')
    Run('reg add "HKLM\software\policies\microsoft\windows\DeviceGuard" /v "LsaCfgFlags" /t REG_DWORD /d 0 /f')
    Run('reg add "HKLM\System\CurrentControlSet\Control\DeviceGuard" /v "EnableVirtualizationBasedSecurity" /t REG_DWORD /d 0 /f')
}

highPerformanceF(*) {
    if(!confAdmin()){
        return
    }
    Run('powercfg -duplicatescheme 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c')
}

pauseUpdate2042F(*) {
    if(confAdmin()){
        Run('reg add "HKLM\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings" /v "PauseFeatureUpdatesStartTime" /t REG_SZ /d "2023-05-08T09:59:52Z" /f')
        Run('reg add "HKLM\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings" /v "PauseFeatureUpdatesEndTime" /t REG_SZ /d "2042-07-07T09:59:52Z" /f')
        Run('reg add "HKLM\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings" /v "PauseQualityUpdatesStartTime" /t REG_SZ /d "2023-05-08T09:59:52Z" /f')
        Run('reg add "HKLM\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings" /v "PauseQualityUpdatesEndTime" /t REG_SZ /d "2042-07-07T09:59:52Z" /f')
        Run('reg add "HKLM\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings" /v "PauseUpdatesStartTime" /t REG_SZ /d "2023-05-08T09:59:52Z" /f')
        Run('reg add "HKLM\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings" /v "PauseUpdatesExpiryTime" /t REG_SZ /d "2042-07-07T09:59:52Z" /f')
        Run('reg add "HKLM\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings" /v "FlightSettingsMaxPauseDays" /t REG_DWORD /d 7000 /f')
    }
    
}

fixNetDiscoverF(*) {
    if(!confAdmin()){
        return
    }
    services := ["Dnscache", "LanmanWorkstation", "LanmanServer", "SSDPSRV", "FDResPub", "fdPHost", "upnphost"]
    for svc in services {
        RunWait('sc config "' svc '" start= auto')
        RunWait('net stop /Y "' svc '"')
        RunWait('net start "' svc '"')
    }
}

enableLPDF(*) {
    confAdmin
    RunWait("powershell -Command `"Enable-WindowsOptionalFeature -Online -FeatureName 'Printing-Foundation-LPDPrintService' -All -NoRestart`"")
    RunWait("powershell -Command `"Enable-WindowsOptionalFeature -Online -FeatureName 'Printing-Foundation-LPRPortMonitor' -All -NoRestart`"")
    RunWait("net stop spooler /y")
    RunWait("net start spooler /y")
}



allowInsecureGuestAuthF(*) {
    confAdmin
    RunWait('reg add "HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows\LanmanWorkstation" /v AllowInsecureGuestAuth /t REG_DWORD /d 1 /f')
    RunWait("net stop workstation")
    RunWait("net start workstation")
}

closeSessionF(*){
    addr:=InputBox("输入要断开会话的地址","断开会话","w300 h100","\\192.168.")
    if(addr.Result == "OK" && addr.Value != ""){
        command := 'net session ' addr.Value ' /delete'
        try {
            RunWait(command)
        }
    }
}
shareInfoF(*) {
    shareInfoGui := Gui("+Resize")
    shareInfoGui.Title := "共享信息"
    global shareEdit := shareInfoGui.Add("Edit", "x10 y10 w800 h600 ReadOnly BackgroundFFFFFF", "")

    btShareSession := shareInfoGui.Add("Button", "x10 y+5 w90", "共享会话")
    btShareSession.OnEvent("Click", (*) => shareEdit.Text := RunCmd("net session"))

    btCloseSession := shareInfoGui.Add("Button", "x+5 yp w90", "关闭会话")
    btCloseSession.OnEvent("Click", closeSessionF)

    ; 关闭全部会话
    btCloseAllSessions := shareInfoGui.Add("Button", "x+5 yp w90", "关闭全部会话")
    btCloseAllSessions.OnEvent("Click", (*) => shareEdit.Text := RunCmd("net session /delete /y"))

    btOpenFile := shareInfoGui.Add("Button", "x+5 yp w90", "打开的文件")
    btOpenFile.OnEvent("Click", (*) => shareEdit.Text := openFileF())

    ; 将控件引用存储在自定义对象中
    ; GuiData := {
    ;     shareEdit: shareEdit,
    ;     btShareSession: btShareSession,
    ;     btOpenFile: btOpenFile
    ; }

    ; 绑定大小事件并将GuiData传递给回调
    ; shareInfoGui.OnEvent("Size", (GuiObj, MinMax, Width, Height) => Gui_Size(GuiObj, MinMax, Width, Height, GuiData))

    shareInfoGui.Show
}

; GUI大小调整回调
Gui_Size(GuiObj, MinMax, Width, Height, GuiData) {
    ; global shareEdit
    ; Access controls from GuiData
    shareEdit := GuiData.shareEdit
    btShareSession := GuiData.btShareSession
    btOpenFile := GuiData.btOpenFile

    ; 计算边距和按钮高度
    margin := 10
    buttonHeight := 30  ; 假定按钮高度

    ; 调整编辑控件大小，为边距和按钮留出空间
    editHeight := Height - margin * 2 - buttonHeight - 5  ;5是间距
    shareEdit.Move(margin, margin, Width - margin * 2, editHeight)

    ; 调整按钮位置
    btShareSession.Move(margin, margin + editHeight + 5)
    btOpenFile.Move(margin + 90 + 5, margin + editHeight + 5)  ; 90是按钮宽度，5是间距
}

openFileF() {
    ; 获取用户输入的部分路径关键词
    pathKeyword := InputBox("请输入部分路径关键词:", "路径搜索", "w300 h100")
    ; 如果用户点击取消，直接返回空字符串
    if (pathKeyword.Result != "OK") {
        return "用户取消操作！"
    }
    ; 构建 PowerShell 命令
    command := buildPowerShellCommand(pathKeyword.Value)
    try {
        ; 执行命令并获取结果
        result := RunCmd(command)
        if (result != "") {
            return result 
        }
    } catch as err {
        ; 处理命令执行失败的情况
        return "执行命令时出错: " . err.Message
    }
    return "无打开的共享文件！" 
}

; 构建 PowerShell 命令的辅助函数
buildPowerShellCommand(keyword) {
    if (keyword != "") {
        return 'powershell -Command "Get-SmbOpenFile | Where-Object -Property Path -Like *' . keyword . '* | Select-Object ClientUserName,Path | Sort-Object Path | Format-Table"'
    }
    return 'powershell -Command "Get-SmbOpenFile | Select-Object ClientUserName,Path | Sort-Object Path"'
}

AdvancedStartup(*) {
    result := MsgBox("确定要进入高级启动模式吗？`n系统将立即重启进入高级启动选项。", "高级启动确认", "OKCancel 4096")
    if (result = "OK") {
        Run('shutdown /r /o /f /t 0')
    }
}

Frecovery(*){
    confAdmin()
    RunWait("sfc /scannow")
    RunWait("DISM /Online /Cleanup-Image /RestoreHealth")
}

toAdmin(*){
    if (!A_IsAdmin) {
        ; 询问用户是否要以管理员权限重启
        result := MsgBox("是否要以管理员权限重启脚本？", "权限请求", "YesNo 4096")
        ; 如果用户选择"是"，则以管理员权限重启
        if result = "Yes"
        {
            Run "*RunAs " A_ScriptFullPath
            ExitApp
        }
    }else{
        MsgBox("您已以管理员权限运行脚本！`n无需切换", "管理员权限", "OK 4096")
    }
}
confAdmin(*){
    if (!A_IsAdmin) {
        ; 询问用户是否要以管理员权限重启
        result := MsgBox("是否要以管理员权限重启脚本？", "权限请求", "YesNo 4096")
        ; 如果用户选择"是"，则以管理员权限重启
        if result = "Yes"
        {
            Run "*RunAs " A_ScriptFullPath
            ExitApp
        }else{
            return false
        }
    }else{
        return true
    }
}
printqueueF(*){
    if (!confAdmin()) {
        return
    }
    RunWait("net stop Spooler")
    RunWait('cmd /c del /F /Q "%windir%\System32\spool\PRINTERS\*.*"')
    RunWait("net start Spooler")
    MsgBox("打印服务已重启`n打印队列已清理！", "打印队列清理", "OK 4096")
}
delThisPCsIconF(*){
    ; 删除NameSpace项
    RunWait('Reg.exe delete "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace" /f')
    confAdmin()
    RunWait('Reg.exe delete "HKLM\Software\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace" /f')
    ; 重建NameSpace项
    RunWait('Reg.exe add "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace" /f')
}
controlPBigIconF(*){
    RunWait('reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\ControlPanel" /v "AllItemsIconView" /t REG_DWORD /d "0" /f')
    RunWait('reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\ControlPanel" /v "StartupPage" /t REG_DWORD /d "1" /f')
}
BanWSearch(*){
    confAdmin()
    RunWait("sc stop WSearch")
    RunWait("sc config WSearch start= disabled")
}
noAutoPlayF(*){
    RunWait('reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\AutoplayHandlers" /v "DisableAutoplay" /t REG_DWORD /d "1" /f')
    RunWait('reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer" /v "NoDriveTypeAutoRun" /t REG_DWORD /d "127" /f')
    confAdmin()
    RunWait('reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer" /v "NoDriveTypeAutoRun" /t REG_DWORD /d "127" /f')
    RunWait("Config ShellHWDetection Start= disabled")
    RunWait("net stop ShellHWDetection")

}
hide7LibF(*){
    confAdmin()
    keys := [
        "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FolderDescriptions\{7d83ee9b-2244-4e70-b1f5-5393042af1e4}\PropertyBag",
        "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FolderDescriptions\{B4BFCC3A-DB2C-424C-B029-7FE99A87C641}\PropertyBag",
        "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FolderDescriptions\{f42ee2d3-909f-4907-8871-4c22fc0bf756}\PropertyBag",
        "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FolderDescriptions\{0ddd015d-b06c-45d5-8c4c-f59713854639}\PropertyBag",
        "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FolderDescriptions\{35286a68-3c57-41a1-bbb1-0eae73d76c95}\PropertyBag",
        "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FolderDescriptions\{a0c69a99-21c8-4671-8703-7934162fcf1d}\PropertyBag",
        "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FolderDescriptions\{31C0DD25-9439-4F12-BF41-7FF4EDA38722}\PropertyBag",
        "HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Explorer\FolderDescriptions\{7d83ee9b-2244-4e70-b1f5-5393042af1e4}\PropertyBag",
        "HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Explorer\FolderDescriptions\{B4BFCC3A-DB2C-424C-B029-7FE99A87C641}\PropertyBag",
        "HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Explorer\FolderDescriptions\{f42ee2d3-909f-4907-8871-4c22fc0bf756}\PropertyBag",
        "HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Explorer\FolderDescriptions\{0ddd015d-b06c-45d5-8c4c-f59713854639}\PropertyBag",
        "HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Explorer\FolderDescriptions\{35286a68-3c57-41a1-bbb1-0eae73d76c95}\PropertyBag",
        "HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Explorer\FolderDescriptions\{a0c69a99-21c8-4671-8703-7934162fcf1d}\PropertyBag",
        "HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Explorer\FolderDescriptions\{31C0DD25-9439-4F12-BF41-7FF4EDA38722}\PropertyBag"
    ]
    for _, key in keys {
        RunWait('reg add "' key '" /v "ThisPCPolicy" /t REG_SZ /d "Hide" /f')
    }
}
showThisPCF(*){
    RunWait('reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\NewStartPanel" /v "{20D04FE0-3AEA-1069-A2D8-08002B30309D}" /t REG_DWORD /d "0" /f')
    confAdmin()
    RunWait('reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\NewStartPanel" /v "{20D04FE0-3AEA-1069-A2D8-08002B30309D}" /t REG_DWORD /d "0" /f')
}
copyPathF(*){
    ; 删除注册表项
    Run('reg delete "HKCR\AllFilesystemObjects\shell\CopyAsPath" /v "HideBasedOnVelocityId" /f')
    Run('reg delete "HKCR\AllFilesystemObjects\shell\CopyAsPath" /v "LegacyDisable" /f')
    Run('reg delete "HKCR\AllFilesystemObjects\shell\CopyAsPath" /v "ProgrammaticAccessOnly" /f')
    ; 添加注册表项
    Run('reg add "HKCR\AllFilesystemObjects\shell\CopyAsPath" /v "MUIVerb" /t REG_SZ /d "@shell32.dll,-30329" /f')
    Run('reg add "HKCR\AllFilesystemObjects\shell\CopyAsPath" /v "Icon" /t REG_SZ /d "imageres.dll,-5302" /f')
    Run('reg add "HKCR\AllFilesystemObjects\shell\CopyAsPath\Command" /ve /t REG_SZ /d "mshta vbscript:clipboarddata.setdata(\"text\",\"%%1\")(close)" /f')
}
addRestartExplorerF(*){
    Run('reg add "HKCR\Directory\Background\shell\RestartExplorer" /ve /t REG_SZ /d "重启资源管理器" /f')
    Run('reg add "HKCR\Directory\Background\shell\RestartExplorer" /v "Icon" /t REG_SZ /d "C:\Windows\explorer.exe,0" /f')
    Run('reg add "HKCR\Directory\Background\shell\RestartExplorer\Command" /ve /t REG_SZ /d "\"%COMSPEC%\" /c taskkill /im explorer.exe /f & start explorer" /f')
}
addAdminOpenF(*){
    confAdmin()
    Run('Reg.exe add "HKLM\SOFTWARE\Classes\Directory\background\shell\RunasCmd" /v "MUIVerb" /t REG_SZ /d "@shell32.dll,-37444" /f')
    Run('Reg.exe add "HKLM\SOFTWARE\Classes\Directory\background\shell\RunasCmd" /v "Icon" /t REG_SZ /d "imageres.dll,-5324" /f')
    Run('Reg.exe add "HKLM\SOFTWARE\Classes\Directory\background\shell\RunasCmd" /v "NoWorkingDirectory" /t REG_SZ /d "" /f')
    Run('Reg.exe add "HKLM\SOFTWARE\Classes\Directory\background\shell\RunasCmd\Command" /ve /t REG_SZ /d "mshta vbscript:createobject(\"shell.application\").shellexecute(\"cmd.exe\",\"/s /k pushd \"\"%%v\"\"\",\"\",\"runas\",1)(close)" /f')
}
manualUpdateF(*) {
    confAdmin()
    RunWait('reg add "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" /v "AUOptions" /t REG_DWORD /d "2" /f ')
    RunWait('reg delete "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" /v "NoAutoUpdate" /f')
}
DisSysMain(*) {
    confAdmin()
    RunWait("sc stop SysMain")
    RunWait("sc config SysMain start= disabled")
}

closebitlockerF(*) {
    confAdmin()
    ; 获取所有盘符
    drives := DriveGetList()
    ; 遍历每个盘符
    loop parse drives {
        RunWait("manage-bde -off " A_LoopField ":")
    }
}

GetIPInfo(*) {
    IPinfoGUI := Gui()
    IPinfoGUI.SetFont(, font)
    IPinfoGUI.Title := "IP信息"

    ; 添加 Edit 控件，设置宽度和高度，显示多行文本
    global EditCtrl := IPinfoGUI.Add("Edit", "w600 h600 ReadOnly BackgroundFFFFFF", "")

    ; 添加关闭按钮，并设置为默认焦点
    BtnClose := IPinfoGUI.Add("Button", "w80 Default", "关闭")
    BtnClose.OnEvent("Click", (*) => IPinfoGUI.Destroy())

    ; 按钮，查看全部信息
    BtnShowAll := IPinfoGUI.Add("Button", "x+5 yp w80", "查看全部")
    BtnShowAll.OnEvent("Click", (*) => FreshGui("ipconfig /all"))

    ; 按钮，查看简约信息
    BtnShowSimple := IPinfoGUI.Add("Button", "x+5 yp w80", "简约信息")
    BtnShowSimple.OnEvent("Click", (*) => EditCtrl.Value := RunCmd("ipconfig"))

    ; 按钮，查看DNS缓存
    BtnShowDNS := IPinfoGUI.Add("Button", "x+5 yp w80", "DNS缓存")
    BtnShowDNS.OnEvent("Click", (*) => EditCtrl.Value := RunCmd("ipconfig /displaydns"))

    ; 按钮，查看ARP信息
    BtnShowDNS := IPinfoGUI.Add("Button", "x+5 yp w80", "ARP缓存")
    BtnShowDNS.OnEvent("Click", (*) => EditCtrl.Value := RunCmd("arp -a"))

    ; 按钮，查看路由表信息
    BtnShowRoute := IPinfoGUI.Add("Button", "x+5 yp w80", "路由表")
    BtnShowRoute.OnEvent("Click", (*) => EditCtrl.Value := RunCmd("route print"))

    ; 按钮，发起Ping
    BtnPing := IPinfoGUI.Add("Button", "x+5 yp w80", "Ping")
    BtnPing.OnEvent("Click", (*) => PingF())

    ; 第二行
    ; 按钮，导出, 保存到txt文件，用户选择保存路径
    BtnExport := IPinfoGUI.Add("Button", "x10 y+5 w80", "导出")
    BtnExport.OnEvent("Click", (*) => ExportIPInfo(EditCtrl.Value))


    ; 按钮，查看端口
    BtnPort := IPinfoGUI.Add("Button", "x+5 yp w80", "查看端口")
    BtnPort.OnEvent("Click", (*) => EditCtrl.Value := RunCmd("netstat -ano"))

    ; 按钮，重置Winsock
    BtnResetWinsock := IPinfoGUI.Add("Button", "x+5 yp w80", "重置Winsock")
    BtnResetWinsock.OnEvent("Click", (*) => (RunCmd("netsh winsock reset"), EditCtrl.Value := "Winsock 已重置！"))

    ; 按钮，清除DNS缓存
    BtnFlushDNS := IPinfoGUI.Add("Button", "x+5 yp w80", "清除DNS缓存")
    BtnFlushDNS.OnEvent("Click", (*) => ( EditCtrl.Value := RunCmd("ipconfig /flushdns")))

    ; 按钮，清除ARP缓存
    BtnFlushARP := IPinfoGUI.Add("Button", "x+5 yp w80", "清除ARP缓存")
    BtnFlushARP.OnEvent("Click", (*) => (RunCmd("arp -d"), EditCtrl.Value := "ARP缓存已清除！"))

    ; 按钮，清除路由表
    BtnFlushRoute := IPinfoGUI.Add("Button", "x+5 yp w80", "清除路由表")
    BtnFlushRoute.OnEvent("Click", (*) => (RunCmd("route -f"), EditCtrl.Value := "路由表已清除！"))

    ; 按钮，Ping多台
    BtnPingMulti := IPinfoGUI.Add("Button", "x+5 yp w80", "Ping多台")
    BtnPingMulti.OnEvent("Click", BtnPingMultiF)

    ; 第二行
    ; 按钮，释放IP
    BtnReleaseIP := IPinfoGUI.Add("Button", "x10 y+5 w80", "释放IP")
    BtnReleaseIP.OnEvent("Click", (*) => ( EditCtrl.Value := RunCmd("ipconfig /release")))

    ; 按钮，刷新IP
    BtnRefreshIP := IPinfoGUI.Add("Button", "x+5 yp w80", "刷新IP")
    BtnRefreshIP.OnEvent("Click", (*) => (EditCtrl.Value := RunCmd("ipconfig /renew")))


    ; 显示 GUI 时将焦点设置到按钮上
    IPinfoGUI.Show()
    ; EditCtrl.Value := RunCmd("ipconfig")
    BtnClose.Focus()  ; 设置焦点到关闭按钮
}
PingF(*){
    ; 获取用户输入的IP地址，默认值为192.168.
    IP := InputBox("请输入要Ping的IP地址：", "Ping测试", , "192.168.")
    if (IP.Result = "OK" && IP.Value != "") {
        ; 执行Ping命令并显示结果
        Run("ping " IP.Value " -t")
    }
}

BtnPingMultiF(*){
    pingMultiGui := Gui()
    pingMultiGui.Title := "Ping多个IP"
    pingMultiGui.Add("Text", , "起始IP:")
    ipStart := pingMultiGui.Add("Edit", "w110", "192.168.20.1")
    pingMultiGui.Add("Text", "xp y+5", "结束IP:")
    ipEnd := pingMultiGui.Add("Edit", "xp y+5 w110", "192.168.20.5")
    
    okButton := pingMultiGui.Add("Button", "x10 y+10 w80", "开始Ping")
    okButton.OnEvent("Click", (*)=>PingMultiF(ipStart.Value,ipEnd.Value))
    
    pingMultiGui.Show()
}
; PingMultiF函数，用于执行Ping多个IP的操作
PingMultiF(ipStart,ipEnd) {
    ; 检查输入的IP地址是否有效, 正则表达式ipStart和ipEnd都符合IP地址的格式
    if (!RegExMatch(ipStart, "^(?:\d{1,3}\.){3}\d{1,3}$")){
        MsgBox("起始IP地址无效！", "错误", "OK Icon!")
    }else if (!RegExMatch(ipEnd, "^(?:\d{1,3}\.){3}\d{1,3}$")){
        MsgBox("结束IP地址无效！", "错误", "OK Icon!") 
    }else{
        ; 提取起始IP的前三个数字
        ipStartPrefix := RegExReplace(ipStart, "\.\d+$", "")
        ; 提取结束IP的前三个数字
        ipEndPrefix := RegExReplace(ipEnd, "\.\d+$", "")
        ; 提取起始IP的最后一段数字
        ipStartLast := RegExReplace(ipStart, "^.*\.", "")
        ; 提取结束IP的最后一段数字
        ipEndLast := RegExReplace(ipEnd, "^.*\.", "")
        ; 检查起始IP和结束IP的前三个数字是否相同
        if (ipStartPrefix != ipEndPrefix) {
            MsgBox("起始IP和结束IP的前三个数字必须相同！", "错误", "OK Icon!") 
        }else if (ipStartLast > ipEndLast) {
            MsgBox("起始IP不能大于结束IP！", "错误", "OK Icon!") 
        }else{
            ; 创建结果GUI
            resultGui := Gui()
            resultGui.Title := "Ping多个IP结果"
            resultEdit := resultGui.Add("Edit", "w600 h400 ReadOnly", "")
            
            ; 逐个Ping IP地址范围
            result := ""
            startNum := Integer(ipStartLast)
            endNum := Integer(ipEndLast)
            
            Loop (endNum - startNum + 1) {
                currentIP := ipStartPrefix "." (startNum + A_Index - 1)
                ; Run("ping -n 1 " currentIP)
                result .= "Pinging " currentIP ":`n"
                result .= RunCmd("ping -n 1 " currentIP) "`n`n"
            }
            
            ; 显示结果
            resultEdit.Value := result
            resultGui.Show()
        }
    }


}

; 导出IP信息到txt文件, 保存到用户选择的路径
ExportIPInfo(txtinfo) {
    ; 检查输入内容是否为空
    if (txtinfo = "") {
        MsgBox("没有可导出的内容！", "提示", "OK Icon!")
        return
    }

    ; 使用 FileSelect 打开保存文件对话框
    ; S16: 保存对话框，带覆盖确认
    ; 默认路径为桌面，默认文件名包含时间戳
    filePath := FileSelect("S16", A_Desktop "\IP信息_" . FormatTime(A_Now, "yyyyMMdd_HHmmss") . ".txt",
        "保存 IP 信息", "文本文件 (*.txt)")

    ; 如果用户取消保存操作，则退出
    if (filePath = "") {
        return
    }

    ; 尝试写入文件并处理可能的错误
    try {
        ; "w" 模式表示写入（覆盖现有文件）
        file := FileOpen(filePath, "w")
        file.Write(txtinfo)
        file.Close()  ; 关闭文件句柄
        ; MsgBox("导出成功！文件已保存到:`n" . filePath, "成功", "OK Iconi")
        Run(filePath)  ; 打开导出的文件
    } catch as err {
        MsgBox("导出失败！错误信息: " . err.Message, "错误", "OK Icon!")
    }
}

; 执行cmd命令并获取结果
; RunCmd(command) {
;     ; 创建 GUI 显示“正在获取数据，请等待...”
;     guiWait := Gui("+AlwaysOnTop -SysMenu")  ; 创建一个置顶、无系统菜单的窗口
;     guiWait.Title := "请稍候"  ; 设置窗口标题
;     guiWait.Add("Text", , "正在执行命令，请等待...")
;     guiWait.Show("xCenter yCenter")  ; 显示在屏幕中央

;     ; 执行命令
;     shell := ComObject("WScript.Shell")
;     exec := shell.Exec(A_ComSpec " /c " command)
;     result := exec.StdOut.ReadAll()

;     ; 获取结果后销毁 GUI
;     guiWait.Destroy()

;     return result
; }

; 执行cmd命令并获取结果
; RunCmd(command) {
;     shell := ComObject("WScript.Shell")
;     exec := shell.Exec(A_ComSpec " /c " command)
;     result := exec.StdOut.ReadAll()
;     return result
; }

; RunCmd(command) {
;     ; 创建临时文件
;     tempFile := A_Temp "\\ahk_cmd_" A_TickCount ".txt"
    
;     ; 执行命令并重定向输出到文件
;     shell := ComObject("WScript.Shell")
;     exec := shell.Exec(A_ComSpec " /c " command " > " tempFile " 2>&1")
    
;     ; 等待进程完成
;     while (exec.Status = 0) {
;         Sleep(50)
;     }
    
;     ; 读取文件内容
;     try {
;         result := FileRead(tempFile)
;         FileDelete(tempFile)
;         return result
;     } catch Error as e {
;         return "读取结果文件时发生错误: " . e.Message
;     }
; }

RunCmd(command) {
    tempFile := A_Temp "\\ahk_cmd_" A_TickCount ".txt"
    RunWait('cmd /c ' command ' > "' tempFile '"', , "Hide")
    try {
        result := FileRead(tempFile)
        FileDelete(tempFile)
        return result
    } catch Error as e {
        return "读取结果文件时发生错误: " . e.Message
    }
}

FreshGui(cmd){
    global EditCtrl
    EditCtrl.Value:=RunCmd(cmd)
}

; Edge配置清空函数
EdgeConfigClear(*) {
    Result := MsgBox("是否清空Edge配置？`nEdge浏览器的书签、保存密码、登录状态都将丢失！！！", "Edge配置清空", "OKCancel 4096")
    if (Result = "OK") {
        if (FileExist("%localappdata%\Microsoft\Edge\User Data")) {
            RunWait('cmd /c del /q "%localappdata%\Microsoft\Edge\User Data"')
            MsgBox("Edge配置已清空！", "Edge配置清空", "OK 4096")
        } else {
            MsgBox("Edge配置已清空！", "Edge配置清空", "OK 4096")
        }
    }

}

; 访问共享
ToShared(*) {
    ToSharedGui := Gui()
    ToSharedGui.Title := "访问共享"
    ToSharedGui.Add("Text", , "请输入共享路径:")
    sharePath := ToSharedGui.Add("Edit", "w110", "\\192.168.")
    okButton := ToSharedGui.Add("Button", "w80", "确定")
    ; okButton.OnEvent("Click", (*) => Run("explorer " sharePath.Text))
    okButton.OnEvent("Click", (*) => startToShare(sharePath.Text))
    ToSharedGui.Show()
}
; 打开共享目录
startToShare(url) {
    if (url == "" or url == "\\192.168.") {
        MsgBox("请输入共享路径！", "访问共享", "OK 4096")
        return
    } else {
        Run("explorer " url)
    }
}


; 清理temp目录
DelTempF(*) {
    RunWait('cmd /c del /q "%temp%\*"')
    RunWait('cmd /c for /d %i in (%temp%\*) do rd /s /q "%i"')
    MsgBox("temp目录已清理！", "清理temp目录工具", "OK 4096")
}

; 清理图标缓存
DelIconCacheF(*) {
    confAdmin()
    RunWait('cmd /c del /q "%localappdata%\Microsoft\Windows\Explorer\*"')
    Result := MsgBox("图标缓存已清理！`n是否重启资源管理器以应用更改？", "提示", "OKCancel 4096")
    if (Result = "OK") {
        RunWait('powershell -Command "Get-Process explorer | Stop-Process -Force"')
        Run('explorer')
    }
}

; 按钮点击事件处理函数
DiskCheck(*) {
    ; 获取所有盘符
    drives := DriveGetList()

    ; 创建选择盘符的 GUI
    driveGui := Gui()
    driveGui.Title := "选择盘符"
    driveGui.Add("Text", , "请选择一个盘符进行检查:")

    ; 添加下拉列表
    driveList := driveGui.Add("DropDownList", "w100")

    ; 将盘符字符串拆分为单个字符并添加到下拉列表
    driveList.Add(StrSplit(drives))

    ; 添加确定按钮
    okButton := driveGui.Add("Button", "w80", "确定")
    okButton.OnEvent("Click", OkButtonClick)

    ; 显示选择盘符的 GUI
    driveGui.Show()

    ; 确定按钮点击事件处理函数
    OkButtonClick(*) {
        ; 获取选择的盘符
        selectedDrive := driveList.Text
        if selectedDrive == "" {
            MsgBox("请选择一个盘符！", "磁盘检查工具", "OK 4096")
            return
        }

        ; 关闭选择盘符的 GUI
        driveGui.Destroy()

        ; 执行 chkdsk 命令
        RunWait("chkdsk " selectedDrive ": /f")

        ; 提示用户检查完成
        MsgBox("磁盘检查已完成！", "磁盘检查工具", "OK 4096")
    }
}

delNetUseF(*) {
    RunWait('cmd /c net use * /del /y')
    MsgBox("网络连接已删除！`n但凭据缓存可能需要注销才能更新！", "删除网络连接", "OK 4096")
}
PowerF(*) {
    powerGui := Gui("+AlwaysOnTop")
    powerGui.SetFont(, font)
    powerGui.Title := "电源管理"
    ; 电源选项
    powercfgcpl := powerGui.Add("Button", "x+5 yp w90", "电源选项")
    powercfgcpl.OnEvent("Click", (*) => Run("powercfg.cpl"))
    ; 电源设置
    powercfg := powerGui.Add("Button", "x+5 yp w90", "电源设置")
    powercfg.OnEvent("Click", (*) => Run("ms-settings:powersleep"))
    ; 新一行
    ; 快速启动开关
    GroupBoxQuickStart := powerGui.Add("GroupBox", "x10 y30 w90 h50 Section", "快速启动")
    quickStart := powerGui.Add("Button", "xs+5 ys+18 w35", "开")
    quickStart.OnEvent("Click", (*) => quickStartF("on"))
    quickStartoff := powerGui.Add("Button", "xs+50 ys+18 w35", "关")
    quickStartoff.OnEvent("Click", (*) => quickStartF("off"))
    ; 新一行
    ; 启用【高性能】
    highPerformance := powerGui.Add("Button", "x17 y85", "启用高性能")
    highPerformance.OnEvent("Click", highPerformanceF)


    ; 休眠开关
    GroupBoxSleep := powerGui.Add("GroupBox", "x110 y30 w90 h50 Section", "休眠")
    hibernate := powerGui.Add("Button", "xs+5 ys+18 w35", "开")
    hibernate.OnEvent("Click", (*) => hibernateSwitchF("on"))
    hibernateoff := powerGui.Add("Button", "xs+50 ys+18 w35", "关")
    hibernateoff.OnEvent("Click", (*) => hibernateSwitchF("off"))


    powerGui.Show()
}
quickStartF(flag) {
    confAdmin()
    if (flag = "on") {
        ExitCode := RunWait('cmd /c reg add "HKLM\SYSTEM\ControlSet001\Control\Session Manager\Power" /v "HiberbootEnabled" /t REG_DWORD /d "1" /f')
        if (ExitCode != 0) {
            MsgBox("快速启动开启失败！退出代码: " . ExitCode, "电源管理", "OK 4096")
        }
    } else {
        ExitCode := RunWait('reg add "HKLM\SYSTEM\ControlSet001\Control\Session Manager\Power" /v "HiberbootEnabled" /t REG_DWORD /d "0" /f')
        if (ExitCode != 0) {
            MsgBox("快速启动关闭失败！退出代码: " . ExitCode, "电源管理", "OK 4096")
        }
    }
}
hibernateSwitchF(flag) {
    confAdmin()
    if (flag = "on") {
        ExitCode := RunWait('powercfg /h on')
        if (ExitCode != 0) {
            MsgBox("休眠开启失败！退出代码: " . ExitCode, "电源管理", "OK 4096")
        }
    } else if (flag = "off") {
        ExitCode := RunWait('powercfg /h off')
        if (ExitCode != 0) {
            MsgBox("休眠关闭失败！退出代码: " . ExitCode, "电源管理", "OK 4096")
        }
    }
}